#pragma once
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_segment_primitive.h>
#include "CGALDefine.h"
class CSortSegment
{
	typedef KCGALWithInfo K;
	typedef K::FT FT;
	typedef K::Ray_3 Ray;
	typedef K::Line_3 Line;
	typedef K::Point_3 Point;
	typedef K::Point_2 Point2;
	typedef K::Segment_2 Segment2;
	typedef K::Segment_3 Segment;
	typedef std::vector<Segment>::iterator Iterator;
	typedef CGAL::AABB_segment_primitive<K, Iterator> Primitive;
	typedef CGAL::AABB_traits<K, Primitive> AABB_Segment_traits;
	typedef CGAL::AABB_tree<AABB_Segment_traits> Tree;
	typedef Tree::Primitive_id Primitive_id;
	typedef Tree::Point_and_primitive_id Point_and_primitive_id;
	typedef boost::optional< Tree::Intersection_and_primitive_id<Segment>::Type > Segment_intersection;
public:
	enum euIntersectionType
	{
		TYPE_ONE_POINT = 0,
		TYPE_SAME
	};

	static  int GetIntersectionNum(euIntersectionType type) 
	{
		return (int)type + 1;
	}

	CSortSegment(){};

	CSortSegment(const ZMVector<ZMPoint3D>& poly);

	void InitTree(const ZMVector<ZMPoint3D>& poly)  ;

	ZMPoint3D ClosePoint(const ZMPoint3D& pnt, int& iPntIndex, ZMPoint3D::euDisType disType = ZMPoint3D::TYPE_3D) const;

	int GetAllIntersection(const ZMPoint3D& pntFrom, const ZMPoint3D& pntTo, ZMVector<int>& iSegIndex, ZMVector<euIntersectionType>& vIntersectionType, ZMVector<ZMPoint3D>& vPntIntersection, ZMPoint3D::euDisType disType = ZMPoint3D::TYPE_3D) const;

	~CSortSegment();
protected:
	vector<Segment>  m_vSegment3, m_vSegment2;
	shared_ptr<Tree> m_pTree2;
	shared_ptr<Tree> m_pTree3;
};

